package nc.bs.mlr.m404099;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import nc.bs.dao.DAOException;
import nc.bs.mlr.pub.AbstractDAO;
import nc.jdbc.framework.processor.ArrayListProcessor;
import nc.jdbc.framework.processor.BeanListProcessor;
import nc.vo.mlr.m404005.DeliverappBVO;
import nc.vo.mlr.m404005.DeliverappHVO;
import nc.vo.mlr.m404099.ReportVO;
import nc.vo.pub.AggregatedValueObject;

public class ServerDAO extends AbstractDAO {

	public ArrayList reportData(HashMap hm) throws DAOException {
		// TODO Auto-generated method stub

		String dhdwid = "".equals(hm.get("dhdwid")) ? "" : hm.get("dhdwid")
				.toString();
		String hth = "".equals(hm.get("hth")) ? "" : hm.get("hth").toString();
		String ywlcid = "".equals(hm.get("ywlcid")) ? "" : hm.get("ywlcid")
				.toString();
		String zxwb = "".equals(hm.get("zxwb")) ? "" : hm.get("zxwb")
				.toString();
		String bmid = "".equals(hm.get("bmid")) ? "" : hm.get("bmid")
				.toString();
		String htrqbegin = "".equals(hm.get("htrqbegin")) ? "" : hm.get(
				"htrqbegin").toString();
		String htrqend = "".equals(hm.get("htrqend")) ? "" : hm.get("htrqend")
				.toString();
		String htrq = "".equals(hm.get("htrq")) ? "" : hm.get("htrq")
				.toString();
		String ywyid = "".equals(hm.get("ywyid")) ? "" : hm.get("ywyid")
				.toString();
		String htlxid = "".equals(hm.get("htlxid")) ? "" : hm.get("htlxid")
				.toString();

		String sql = "select po.cbiztype as ywlcid, "
				+ " v.cgddzl as cgddzl, "
				+ " v.cgddje as cgddje, "
				+ " v.jgl as jgl, "
				+ " v.zyl as zyl, "
				+ " v.rkzl as rkzl, "
				+ " v.cgdhje as cgdhje , "
				+ " v.dpzl as dpzl, "
				+ " v.dpje as dpje, "
				+ " v.xsddl as xsddl, "
				+ " v.tdl as tdl, "
				+ " v.ckl as ckl, "
				+ " v.kpzl as kpzl, "
				+ " v.kpje as kpje, "
				+ " v.wtzl as wtzl, "
				+ " v.tdje as tdje, "
				+ " v.ydbzj as ydbzj, "
				// + " v.yszhk as yszhk, "
				+ " v.ssbzj as ssbzj, "
				+ " v.ysfbzj as ysfbzj, "
				+ " v.ysbzj as ysbzj, "
				+ " v.yshk as yshk, "
				+ " v.sshk as sshk, "
				+ " v.htpjj as htpjj, "
				+ " v.ddbzjin as ddbzjin , "
				+ " (v.htpjj - v.ddbzjin) as ddbzj, "
				+ " v.zxwb as zxwb, "
				+ " v.fy as fy, "
				+ " v.hth as hth, "
				+ " v.htrq as htrq, "
				+ " v.nddlxy as nddlxy, "
				+ " v.dhdwid as dhdwid, "
				+ " v.htzl as htzl, "
				+ " v.htje as htje, "
				+ " v.zcfkrq as zcfkrq, "
				+ " v.ywyid as ywyid, "
				+ " bd_corp.unitname as gs, "
				+ " bd_busitype.businame as ywlc, "
				+ " bd_cubasdoc.custname as ghdw, "
				+ " sm_user.user_name as ywy,v.bmid,bd_deptdoc.deptname as bm,v.htlx as htlx"
				+ " from v_mlr_xshtzxqk_1019_total v "
				+ " inner join (select po_order_b.pk_defdoc8, "
				+ "  sum(nvl(po_order_b.nordernum, 0)) as ddl, "
				+ "  po_order.cbiztype "
				+ "  from po_order "
				+ "  inner join po_order_b on po_order.corderid = "
				+ " po_order_b.corderid "
				+ " where nvl(po_order_b.dr, 0) = 0 "
				+ "  and nvl(po_order.dr, 0) = 0 "
				+ "  group by po_order_b.pk_defdoc8, po_order.cbiztype) po on v.hthid = "
				+ " po.pk_defdoc8 "
				+ " left join bd_corp on v.pk_corp = bd_corp.pk_corp "
				+ " left join bd_busitype on po.cbiztype = bd_busitype.pk_busitype "
				+ " left join bd_cumandoc on v.dhdwid = bd_cumandoc.pk_cumandoc "
				+ " left join bd_cubasdoc on bd_cumandoc.pk_cubasdoc = "
				+ " bd_cubasdoc.pk_cubasdoc "
				+ " left join sm_user on v.ywyid = sm_user.cuserid left join bd_deptdoc on v.bmid=bd_deptdoc.pk_deptdoc where 1=1";

		StringBuffer strsql = new StringBuffer();
		strsql.append(sql);
		if (!"".equals(dhdwid)) {
			strsql.append(" and dhdwid='" + dhdwid + "'");
		}
		if (!"".equals(hth)) {
			strsql.append(" and hth like '%" + hth + "%'");
		}
		if (!"".equals(ywlcid)) {
			strsql.append(" and cbiztype = '" + ywlcid + "'");
		}
		if (!"".equals(zxwb)) {
			strsql.append(" and zxwb = '" + zxwb + "'");
		}
		if (!"".equals(bmid)) {
			strsql.append(" and bmid = '" + bmid + "'");
		}
		if (!"".equals(htrqbegin)) {
			strsql.append(" and htrq >= '" + htrqbegin + "'");
		}
		if (!"".equals(htrqend)) {
			strsql.append(" and htrq <= '" + htrqend + "'");
		}
		if (!"".equals(htrq)) {
			strsql.append(" and htrq = '" + htrq + "'");
		}
		if (!"".equals(ywyid)) {
			strsql.append(" and ywyid = '" + ywyid + "'");
		}
		if (!"".equals(htlxid)) {
			strsql.append(" and htlxid = '" + htlxid + "'");
		}
		ArrayList<ReportVO> al = (ArrayList<ReportVO>) getBaseDAO()
				.executeQuery(strsql.toString(),
						new BeanListProcessor(ReportVO.class));
		return al;
	}
}
